package com.guoyansoft.model.service.impl;

import com.guoyansoft.config.R;
import com.guoyansoft.model.dao.GoodsAndShopDao;
import com.guoyansoft.model.dao.ShopDao;
import com.guoyansoft.model.dao.ShopManagerDao;
import com.guoyansoft.model.pojo.Shop;
import com.guoyansoft.model.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private GoodsAndShopDao goodsAndShopDao;
    @Autowired
    private ShopManagerDao shopManagerDao;
    @Override
    public R selectByPageAndTotalsize(Map<String, Object> params) {
        List<Shop> shopList=shopDao.selectByPage(params);
        long total=shopDao.selectTotalSize(params);
        return R.suc(total,shopList);
    }

    @Override
    public boolean insert(Shop shop) {
        int row= shopDao.insert(shop);
        if(row>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(Integer id) {
        int row1=shopDao.delete(id);
        int row2=goodsAndShopDao.delete(id);
        int row3=shopManagerDao.delete1(id);
        if(row1>0&&row2>0&&row3>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(Shop shop) {
        int row=shopDao.update(shop);
        if(row>0){
            return true;
        }
        return false;
    }



    @Override
    public R selectById(Integer shopId) {
        Shop shop= shopDao.selectById(shopId);
        return shop!=null?R.suc(shop):R.fail();
    }

    @Override
    public R selectAll(Map<String,Object> params) {
        List<Shop> shops = shopDao.selectAll(params);
        long total=shopDao.selectcount(params);
        return R.suc(total,shops);
    }

    @Override
    public Shop selectByName(String name) {
        Shop shop = shopDao.selectByName(name);
        System.out.println(shop);
        return shop;
    }
}
